package com.hxkj.controller;


import com.github.pagehelper.PageInfo;
import com.hxkj.domain.po.DictItem;
import com.hxkj.service.DictItemService;
import com.platform.common.domain.result.ParameterDataStruct;
import com.platform.common.domain.result.ResultDataStruct;
import com.platform.common.domain.result.ResultMessageStruct;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.concurrent.Callable;

/**
 * 二级字典列表    控制层
 * <p>
 * Created by zzx on 2018/5/15.
 */
@RestController
@Slf4j
@RequestMapping("/dictItem")
public class DictItemController {

    @Autowired
    private  DictItemService dictItemService;

    /**
     * 获取一个字典列表  二 级（子类）
     * @param
     * @param
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getlist", method = RequestMethod.POST,consumes  ="application/json;charset=UTF-8")
    public ResultDataStruct<PageInfo> getlist(@RequestBody ParameterDataStruct<DictItem> parameterDataStruct){
        ResultDataStruct resultDataStruct = new ResultDataStruct();
        try {
            PageInfo pageInfo = dictItemService.getDictItemList(parameterDataStruct.getData(),parameterDataStruct.getPageTo());
            resultDataStruct.setCode(200);
            resultDataStruct.setData(pageInfo);
        } catch (Exception e) {
            resultDataStruct.setCode(400);
            resultDataStruct.setData(e.getMessage());
        }
        return resultDataStruct;
    }

    /**
     * 获取一个字典信息  二 级（子类）
     * @param dictItem
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/get", method = RequestMethod.POST,consumes  ="application/json;charset=UTF-8")
    public  Callable<ResultDataStruct<DictItem>> get(@RequestBody DictItem dictItem) throws Exception{
        return() -> dictItemService.getDictItemFromCache(dictItem);
    }

    /**
     * 通过字典明细名称获取字典明细
     * @param dictItem
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getDictItemByDictType", method = RequestMethod.POST,consumes  ="application/json;charset=UTF-8")
    public  Callable<ResultDataStruct<List<DictItem>>> getDictItemByDictType(@RequestBody DictItem dictItem) {
        return() -> dictItemService.getDictItemByDictType(dictItem);
    }

    /**
     * 新增字典      二 级（子类）
     * @param dictItem
     * @return
     * @throws Exception
     */
   @RequestMapping(value = "/save",method = RequestMethod.POST,consumes  ="application/json;charset=UTF-8")
    public  Callable<ResultMessageStruct> saveDictItem(@RequestBody DictItem dictItem)throws  Exception{
        return() -> dictItemService.saveDictItem(dictItem);

   }

    /**
     * 删除一个字典信息   二 级（子类）
     * @param dictItem
     * @return
     * @throws Exception
     */
   @RequestMapping(value = "/remove",method = RequestMethod.POST,consumes  ="application/json;charset=UTF-8")
    public  Callable<ResultMessageStruct> deleteDictItem(@RequestBody DictItem dictItem)throws Exception{
       return() -> dictItemService.deleteDictItem(dictItem);
   }

    /**\
     * 修改一个字典信息   二 级（子类）
     * @param dictItem
     * @return
     * @throws Exception
     */
   @RequestMapping(value = "/modify",method = RequestMethod.POST,consumes  ="application/json;charset=UTF-8")
    public  Callable<ResultMessageStruct> updateDictItem(@RequestBody DictItem dictItem) throws Exception{
       return() -> dictItemService.updateDictItem(dictItem);
   }

    /**
     *禁用一个 二级 字典
     * @param dictItem
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/update",method = RequestMethod.POST,consumes  ="application/json;charset=UTF-8")
    public  Callable<ResultMessageStruct> modifyDictItem(@RequestBody DictItem dictItem) throws Exception{
        return() -> dictItemService.modifyDictItem(dictItem);
    }

    /**
     *  获取一个字典下拉框  二 级（子类）
     * @param dictItem
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/comboBox", method = RequestMethod.POST,consumes  ="application/json;charset=UTF-8")
    public  Callable<ResultDataStruct<List<DictItem>>> comboBox(@RequestBody DictItem dictItem) throws Exception{
        return() -> dictItemService.comboBox(dictItem);
    }
}